import logging
import os
from common.config import cfg
from datetime import datetime
# 创建日志目录
log_dir = cfg['log']['log_dir']
if not os.path.exists(log_dir):
    os.makedirs(log_dir)
# logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 创建访问日志记录器
current_date = datetime.now().strftime('%Y-%m-%d')
access_log_file = os.path.join(log_dir, f'access_{current_date}.log')
access_logger = logging.getLogger('tornado.access')
access_logger.setLevel(logging.INFO)
access_handler = logging.FileHandler(access_log_file)
access_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
access_handler.setFormatter(access_formatter)
access_logger.addHandler(access_handler)
# 创建应用日志记录器
app_log_file = os.path.join(log_dir, f'app_{current_date}.log')
app_logger = logging.getLogger('tornado.application')
app_logger.setLevel(logging.INFO)
app_handler = logging.FileHandler(app_log_file)
app_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
app_handler.setFormatter(app_formatter)
app_logger.addHandler(app_handler)

def logInfo(userid, phonenumber, account_type, msg):
    app_logger.info(f"userid: {userid}, phonenumber: {phonenumber}, account_type: {account_type}, msg: {msg}")